package com.springboot.cotroller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.springboot.model.User;
import com.springboot.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("/find/{id}")
    public @ResponseBody User findById(@PathVariable("id") Integer id){
        User byId = userService.findById(id);
        return byId;
    }

    @RequestMapping("/add")
    public @ResponseBody String add(User user){
        userService.insert(user);
        return "success";
    }

    @DeleteMapping("/delete/{id}")
    public @ResponseBody String delete(@PathVariable("id") Integer id){
        userService.deleteById(id);
        return "success";
    }


    @RequestMapping("{currentPage}/{numbers}")
    public @ResponseBody IPage page(@PathVariable("currentPage") Integer currentPage, @PathVariable("numbers") Integer counts){
        IPage iPage = userService.fingByPage(currentPage, counts);
        return iPage;
    }
}
